using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

[XLua.LuaCallCSharp]
public class MoveTo : MonoBehaviour
{
    private Transform target;
    private float speed = 10f;
    private Action onComplate;

    private void Update()
    {
        Debug.Log("MoveTo:" + target.name + " tag:" + target.tag);
        transform.position = Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * speed);
        if ((transform.position - target.position).sqrMagnitude < 25f)
        {
            onComplate?.Invoke();
            Destroy(this);
        }
    }

    public void SetParams(Transform target, float speed, Action onComplate)
    {
        this.target = target;
        this.speed = speed;
        this.onComplate = onComplate;
    }
}